﻿<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
    <script type="text/javascript" src="../js/zysoft.js"></script>
    <script type="text/javascript" src="../js/victory23soft.js"></script>
    <script type="text/javascript" src="../js/jquery.contextmenu.v2.min.js"></script>
    <script type="text/javascript">
        $(function () {
            console.log("123456");

            /** 替换加载内容 **/
            var spanContent = $("#tempItem").html().format("mengweiwang@163.com", "27", "浙江淳安");
            $("#container").html(spanContent);

            /** 字符串左右拼接（公司内部） **/
            var strvalue = "12";
            console.log($.lpad(strvalue, 8, '0'));
            console.log($.rpad(strvalue, 8, '0'));

            /** 字符串左右拼接（自己扩展） **/
            console.log(strvalue.PadLeft(8, '0'));
            console.log(strvalue.PadRight(8, '0'));

            /** 模拟HashTable **/
            var map = new HashTable();
            map.add("A", "1");
            map.add("B", "2");
            map.add("A", "5");
            map.add("C", "3");
            map.add("A", "4");

            var arrayKey = new Array("1", "2", "3", "4");
            var arrayValue = new Array("A", "B", "C", "D");
            map.add(arrayKey, arrayValue);
            var value = map.getValue(arrayKey);

            var object1 = new MyObject("小4", 23);
            var object2 = new MyObject("小5", 27);

            map.add(object1, "小4");
            map.add(object2, "小5");


            var stuObj = new Object();
            stuObj.studentID = "00001";
            stuObj.name = "张三丰";

            map.add("stuObj", stuObj);

            registerRightClick();

            deleteProperty();
        });

        /*
         * 自定义类*/
        function MyObject(name, age) {
            this.name = name;
            this.toString = function () {
                return this.name;
            };
            this.age = age;
            this.toString = function () {
                return this.age;
            }
        }

        /*
         * 注册右键点击事件
         */
        function registerRightClick() {
            $('span.demo1').contextMenu('myMenu1', {
                bindings: {
                    'open': function (t) {
                        alert('Trigger was ' + t.id + '\nAction was Open');
                    },
                    'email': function (t) {
                        alert('Trigger was ' + t.id + '\nAction was Email');
                    },
                    'save': function (t) {
                        alert('Trigger was ' + t.id + '\nAction was Save');
                    },
                    'delete': function (t) {
                        alert('Trigger was ' + t.id + '\nAction was Delete');
                    }
                }
            });

            /*$(".rightclick").contextMenu('stabox', function (i, e) {
             window.document.oncontextmenu = function () { return false; }
             if (i.which == 3) {
             var x = i.pageX;
             var y = i.pageY;
             $(".stabox").css({ "top": y + "px", "left": x + "px" }).show();

             var selected_zhsz_hpxzdmb_id = $(this).parent().parent().parent().parent().attr("zhsz_hpxzdmb_id");
             $("#hid_zhsz_hpxzdmb_id").val(selected_zhsz_hpxzdmb_id);

             $(".hidIndex").val($(this).index());
             }
             });*/
        }

        /*
         * 如何删除属性
         * */
        function deleteProperty() {
            var objModel = {
                bar: 1,
                foo: 2,
                baz: 3,
                case: 'I am a keyword so I must be notated as a string',
                delete: 'I am a keyword too so me'
            };
            objModel.bar = undefined;
            objModel.foo = null;
            delete objModel.bar;

            for (var i in objModel) {
                if (objModel.hasOwnProperty(i)) {
                    console.log(objModel[i]);
                }
            }
        }

    </script>
</head>

<body>
<!-- 承载数据容器 -->
<div id="container">

</div>

<!-- 右键菜单实例 -->
<p>
    <span class="demo1" id="demo1_yellow" style="background-color: yellowgreen"><b>RIGHT CLICK FOR DEMO</b></span>
    <span class="demo1" id="demo1_green" style="background-color:lightgreen"><b>THIS WORKS TOO</b></span>
</p>
<!-- 数据绑定模板 -->
<div id="tempItem" style="display: none;">
    <span>{0}</span>
    <span>{1}</span>
    <span>{2}</span>
</div>
<!-- 右键点击菜单列表 -->
<div class="contextMenu" id="myMenu1" style="display: none;">
    <ul>
        <li id="open"><img src="../images/folder.png"/> Open</li>
        <li id="email"><img src="../images/email.png"/> Email</li>
        <li id="save"><img src="../images/disk.png"/> Save</li>
        <li id="delete"><img src="../images/cross.png"/> Delete</li>
    </ul>
</div>
</body>


</html>
